<template>
  <el-dialog
    v-model="visible"
    title="质检录入"
    width="800px"
    :before-close="handleClose"
  >
    <el-form :model="form" label-width="120px">
      <el-row>
        <el-form-item label="组号">
          <el-input :model-value="form.group_id" readonly></el-input>
        </el-form-item>
        <el-form-item label="计划号">
          <el-input :model-value="form.plan_id"></el-input>
        </el-form-item>
      </el-row>

      <el-row>
        <el-form-item label="类型">
          <el-input :model-value="form.plan_type" readonly></el-input>
        </el-form-item>
        <el-form-item label="客户">
          <el-input :model-value="form.cus_name"></el-input>
        </el-form-item>
      </el-row>

      <el-row>
        <el-form-item label="规格">
          <el-input :model-value="form.std_name" readonly></el-input>
        </el-form-item>
        <el-form-item label="花色">
          <el-input :model-value="form.color_name"></el-input>
        </el-form-item>
      </el-row>

      <el-form-item label="生产量" style="width: 633px">
        <el-input :model-value="form.arrange_num" readonly></el-input>
      </el-form-item>

      <el-row>
        <el-form-item label="一等品">
          <el-input-number
            :min="0"
            controls-position="right"
            :precision="1"
            :step="1"
            v-model="form.check_1"
          ></el-input-number>
        </el-form-item>

        <el-form-item label="二等品">
          <el-input-number
            :min="0"
            controls-position="right"
            :precision="1"
            :step="1"
            v-model="form.check_2"
          ></el-input-number>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="三等品">
          <el-input-number
            :min="0"
            controls-position="right"
            :precision="1"
            :step="1"
            v-model="form.check_3"
          ></el-input-number>
        </el-form-item>

        <el-form-item label="等外品">
          <el-input-number
            :min="0"
            controls-position="right"
            :precision="1"
            :step="1"
            v-model="form.check_4"
          ></el-input-number>
        </el-form-item>
      </el-row>
      <el-form-item label="质检量" style="width: 633px">
        <el-input :model-value="form.check_num" readonly></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">关闭</el-button>
        <el-button type="primary" @click="exec">保存</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup >
import { reactive, ref, computed, watch } from "vue";
import { tip, get, post, put, del, ddo } from "@/common";

//获取基础信息
const infoList = ref([]);
const cusList = computed(() =>
  infoList.value.filter((item) => item.info_type === 1)
);
const stdList = computed(() =>
  infoList.value.filter((item) => item.info_type === 2)
);
const colorList = computed(() =>
  infoList.value.filter((item) => item.info_type === 3)
);
const getInfoList = () => {
  get("/plan/manager/info").then((result) => {
    infoList.value = result.data;
  });
};

const visible = ref(false);
const open = (item) => {
  for (let prop in item) {
    form[prop] = item[prop];
  }

  getInfoList();
  visible.value = true;
};
const handleClose = (done) => {
  done();
};

const form = reactive({
  group_id: "",
  plan_id: "",
  plan_type: "", // 产品类型
  group_cus:"",
  group_std:"",
  group_color:"",
  cus_name: "",
  std_name: "",
  color_name: "",
  arrange_num: 0,
  check_1: 0,
  check_2: 0,
  check_3: 0,
  check_4: 0,
  check_num: 0,
});

watch(form, (newForm, oldForm) => {
  newForm.check_num =
    newForm.check_1 + newForm.check_2 + newForm.check_3 + newForm.check_4;
});

const emit = defineEmits(["ok"]);
const exec = () => {
  put("/process/check/save/", form, {
    title: "提示",
    message: "您确定保存该质检数据吗？",
  }).then((result) => {
    emit("ok");
    visible.value = false;
    tip.success("更新成功！");
  });
};

defineExpose({ open });
</script>

<style>
</style>